package com.itheima.spring.cyclicDependency2.proxy;

import com.itheima.spring.cyclicDependency2.bean.UserService;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor;

public class MyProxyBeanPostProcessor implements SmartInstantiationAwareBeanPostProcessor {

    public Object getEarlyBeanReference(Object bean, String beanName) throws BeansException {

        // 模拟 UserService 需要创建代理
        if(bean instanceof UserService) {
            JdkDynamicProxy jdkDynamicProxy = new JdkDynamicProxy(bean);
            return  jdkDynamicProxy.getProxy();
        }
        //不需要创建代理的直接返回原始bean
        return bean;
    }
}
